﻿#include <iostream>
using namespace std;

//实现查找⼦串sub在母串src中出现的次数。例如⼦串"ab"在母串"abaabc"中出现2次。
int sub(char const *p1,char const *p2)
{
	int i = 0,n=0;
	int len1 = strlen(p1), len2 = strlen(p2);
	while(i <= (len1 - len2))
	{
		if (strcmp(p1+i,p2)==1&&strcmp(p1+i+1,p2+1)==1)
		{
			n++;
		}
		i++;
	}
	return n;
}

int main()
{
	char a[7] = { "absab" };
	char b[5] = { "ab" };
	cout << sub(a, b);
}